package com.easygem.controller.front;

import com.easygem.common.annotation.ControllerEndpoint;
import com.easygem.common.model.front.TaskPackage;
import com.easygem.common.response.ResponseBean;
import com.easygem.common.vo.front.TaskPackageVO;
import com.easygem.common.vo.system.PageVO;
import com.easygem.front.service.TaskPackageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @author 李鹏志
 * @version 1.0
 * @Description TODO
 * @date 2024/12/25 10:07
 */
@Api(tags = "任务包管理")
@Controller
@Transactional
@RequestMapping("/tasking/taskgoverning")
public class TaskPackageController {
    @Autowired
    private TaskPackageService taskPackageService;
    @ApiOperation(value = "任务包列表", notes = "模糊查询任务包列表")
    @GetMapping("/getAllTaskPackage")
    @ResponseBody
    public ResponseBean<PageVO<TaskPackage>> getAllTaskPackage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                               @RequestParam(value = "pageSize", defaultValue = "7") Integer pageSize,
                                                               TaskPackageVO taskPackageVO
    ){
        PageVO<TaskPackage> taskPackageList = taskPackageService.getAllTaskPackage(pageNum, pageSize, taskPackageVO);
        return ResponseBean.success(taskPackageList);
    }

    /**
     * 根据id查询任务包
     *
     * @param id 任务包id
     * @return 任务包
     */
    @ApiOperation(value = "任务包总数", notes = "查询任务包总数")
    @GetMapping("/getTaskPackageById/{id}")
    @ResponseBody
    public  ResponseBean<TaskPackage> getTaskPackageById(@PathVariable("id")Long id) {
        TaskPackage taskPackage = taskPackageService.getTaskPackageById(id);
        return ResponseBean.success(taskPackage);
    }

    /**
     * 根据任务包id删除任务包
     * @param taskPackageId 任务包id
     * @return 删除的数量
     */
    @ControllerEndpoint(exceptionMessage = "删除任务包失败", operation = "删除任务包")
    @RequiresPermissions("task_package:delete")
    @ApiOperation(value = "删除任务包", notes = "根据任务包id删除任务包")
    @DeleteMapping("/delByTaskPackageId/{taskPackageId}")
    @ResponseBody
    public ResponseBean<Integer> delByTaskPackageId(@PathVariable("taskPackageId") Integer taskPackageId){
        int i = taskPackageService.delByTaskPackageId(taskPackageId);
        return ResponseBean.success(i);
    }

    @PostMapping("/updateTaskPackage")
    @ResponseBody
    public ResponseBean updateTaskPackage(@RequestBody TaskPackage taskPackageVO){
        taskPackageService.updateTaskPackage(taskPackageVO);
        return ResponseBean.success("success");
    }

    /**
     * 进入任务包管理页面
     * @return
     */
    @GetMapping("/index")
    @RequiresPermissions("task_package:view")
    public String index() {
        return "taskPackage/task-package";
    }

    /**
     * 进入文件上传并创建任务包页面
     * @return 页面视图名称
     */
    @GetMapping("/upload-create")
    @RequiresPermissions("task_package:add")
    public String uploadCreate() {
        return "taskPackage/upload-create";
    }

    /**
     * 获取任务包列表
     * @param pageNum 页数
     * @param pageSize 条数
     * @return 任务包分页数据
     */
    @GetMapping("/list")
    @ResponseBody
    @RequiresPermissions("task_package:view")
    public ResponseBean<PageVO<TaskPackage>> getTaskPackageList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                @RequestParam(value = "pageSize", defaultValue = "7") Integer pageSize,
                                                                TaskPackageVO taskPackageVO){
        PageVO<TaskPackage> taskPackageList = taskPackageService.getAllTaskPackage(pageNum, pageSize, taskPackageVO);
        return ResponseBean.success(taskPackageList);
    }
}
